home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / strategy / xshisen-.001 / xshisen-~ / xshisen-1.35 / common.C < prev    next >
C/C++ Source or Header  |  1995-10-22  |  4KB  |  103 lines

  1. #include "components.h"
  2.  
  3. void
  4. PopDownCB(Widget w, XtPointer client_data)
  5. {
  6. #if USE_MOTIF
  7.     XtUnmanageChild(w);
  8. #else /* USE_MOTIF */
  9.     Widget shell = (Widget)client_data;
  10.     XtPopdown(shell);
  11. #endif /* USE_MOTIF */
  12. }
  13.  
  14. void
  15. Message(Pixmap symbol, const char *message, int timeout,
  16.         XtTimerCallbackProc timeout_proc, XtCallbackProc additional_callback)
  17. {
  18. #if USE_MOTIF
  19.     static Widget w;
  20.     static int created = 0;
  21.     XmString str;
  22.  
  23.     if (!created) {
  24.         w = XmCreateMessageDialog(toplevel, "message", NULL, 0);
  25.         XtAddCallback(w, XmNokCallback, (XtCallbackProc)PopDownCB, NULL);
  26.         XtUnmanageChild(XmMessageBoxGetChild(w, XmDIALOG_CANCEL_BUTTON));
  27.         XtUnmanageChild(XmMessageBoxGetChild(w, XmDIALOG_HELP_BUTTON));
  28.         created = 1;
  29.     }
  30.     str = XmStringCreateLtoR((char *)message, XmFONTLIST_DEFAULT_TAG);
  31.     XtVaSetValues(w,
  32.                   XmNmessageString, str,
  33.                   XmNsymbolPixmap, symbol,
  34.                   NULL);
  35.     XmStringFree(str);
  36.     if (additional_callback)
  37.         XtAddCallback(w, XmNokCallback, additional_callback, NULL);
  38.     if (timeout > 0)
  39.         XtAppAddTimeOut(app_context, timeout, timeout_proc, w);
  40.     XtManageChild(w);
  41. #else /* USE_MOTIF */
  42.     static Widget shell, mf, mfl, pix, label, button;
  43.     static int created = 0;
  44.  
  45.     if (!created) {
  46.         Position x, y;
  47.         XtVaGetValues(toplevel, XtNx, &x, XtNy, &y, NULL);
  48.         shell = XtVaCreatePopupShell("message", transientShellWidgetClass, toplevel,
  49.                                      XtNx, x+10,
  50.                                      XtNy, y+10,
  51.                                      NULL);
  52.         mf = XtVaCreateManagedWidget("mf", formWidgetClass, shell,
  53.                                      XtNborderWidth, 0,
  54.                                      NULL);
  55.         mfl = XtVaCreateManagedWidget("mfl", formWidgetClass, mf,
  56.                                       XtNborderWidth, 0,
  57.                                       XtNresizable,   True,
  58.                                       XtNtop,         XawChainTop,
  59.                                       XtNbottom,      XawChainBottom,
  60.                                       XtNleft,        XawChainLeft,
  61.                                       XtNright,       XawChainRight,
  62.                                       NULL);
  63.         pix = XtVaCreateManagedWidget("pix", labelWidgetClass, mfl,
  64.                                       XtNborderWidth, 0,
  65.                                       XtNbitmap,      symbol,
  66.                                       XtNresizable,   True,
  67.                                       XtNtop,         XawChainTop,
  68.                                       XtNbottom,      XawChainTop,
  69.                                       XtNleft,        XawChainLeft,
  70.                                       XtNright,       XawChainLeft,
  71.                                       NULL);
  72.         label = XtVaCreateManagedWidget("label", labelWidgetClass, mfl,
  73.                                         XtNborderWidth, 0,
  74.                                         XtNfromHoriz,   pix,
  75.                                         XtNresizable,   True,
  76.                                         XtNtop,         XawChainTop,
  77.                                         XtNbottom,      XawChainBottom,
  78.                                         XtNleft,        XawChainLeft,
  79.                                         XtNright,       XawChainRight,
  80.                                         NULL);
  81.         button = XtVaCreateManagedWidget("button", commandWidgetClass, mf,
  82.                                          XtNfromVert, mfl,
  83.                                          XtNlabel,    "OK",
  84.                                          XtNtop,      XawChainBottom,
  85.                                          XtNbottom,   XawChainBottom,
  86.                                          XtNleft,     XawChainLeft,
  87.                                          NULL);
  88.         XtAddCallback(button, XtNcallback, (XtCallbackProc)PopDownCB, shell);
  89.     }
  90.     XtVaSetValues(pix,
  91.                   XtNbackgroundPixmap, symbol,
  92.                   NULL);
  93.     XtVaSetValues(label,
  94.                   XtNlabel, message,
  95.                   NULL);
  96.     if (additional_callback)
  97.         XtAddCallback(button, XtNcallback, additional_callback, NULL);
  98.     if (timeout > 0)
  99.         XtAppAddTimeOut(app_context, timeout, timeout_proc, shell);
  100.     XtPopup(shell, XtGrabNone);
  101. #endif /* USE_MOTIF */
  102. }
  103.